package com.ruoyi.system.service.impl.trade;

import com.ruoyi.system.domain.db.basic.BasicMaterials;
import com.ruoyi.system.domain.dto.MaterialStoreDto;
import com.ruoyi.system.domain.vo.MaterialStoreVo;
import com.ruoyi.system.mapper.trade.TradeMaterialUsageMapper;
import com.ruoyi.system.service.ITradeMaterialStoreService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class TradeMaterialStoreServiceImpl implements ITradeMaterialStoreService {


    @Resource
    private TradeMaterialUsageMapper tradeMaterialUsageMapper;
    /**
     * 查询所有
     *
     * @param basicMaterials
     */
    @Override
    public List<MaterialStoreVo> selectAll(BasicMaterials basicMaterials) {
        return tradeMaterialUsageMapper.selectAllMaterialStore(basicMaterials).stream().map(this::dtoToVo).collect(Collectors.toList());

    }

    public MaterialStoreVo dtoToVo (MaterialStoreDto dto){
        MaterialStoreVo materialStoreVo = new MaterialStoreVo();
        materialStoreVo.setMaterialId(dto.getMaterial().getMaterialId());
        materialStoreVo.setMaterialName(dto.getMaterial().getMaterialName());
        materialStoreVo.setMaterialTypeName(dto.getMaterial().getMaterialTypeName());
        materialStoreVo.setApplicationType(dto.getMaterial().getApplicationType());
        materialStoreVo.setQuantity(dto.getQuantity()==null?0:dto.getQuantity());
        return materialStoreVo;


    }
}
